package com.prp.gwt.client.widgets.admin;

import java.util.List;

import com.google.gwt.user.client.ui.DeckPanel;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Hyperlink;
import com.google.gwt.user.client.ui.MultiWordSuggestOracle;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.prp.gwt.client.admin.AdminHistoryHandler;
import com.prp.gwt.client.admin.AdminListener;

public class AdminView extends VerticalPanel {

	private static AdminView instance;
	public static final int ADMINLIST = 0;
	public static final int ROOTLIST = 1;
	public static final int ACCOUNTMANAGEMENT = 2;
	public static final int COMMUNITYLIST = 3;
	public static final int COMMUNITYMEMBER = 4;

	private DeckPanel deckPanel = new DeckPanel();
	private Hyperlink adminList = new Hyperlink("管理员列表", AdminHistoryHandler.ADMINLIST);
	private Hyperlink rootList = new Hyperlink("超级管理员列表", AdminHistoryHandler.ROOTLIST);
	private Hyperlink accountManagement = new Hyperlink("用户帐户管理", AdminHistoryHandler.ACCOUNTMANAGEMENT);
	private Hyperlink communityList = new Hyperlink("社区列表", AdminHistoryHandler.COMMUNITYLIST);
	
	private static MultiWordSuggestOracle emailOracle = new MultiWordSuggestOracle();
	private static MultiWordSuggestOracle nameOracle = new MultiWordSuggestOracle();
	
	public static AdminView getInstance() {
		if (instance == null)
			instance = new AdminView();
		return instance;
	}
	
	@Override
	protected void onLoad() {
		setWidth("100%");
		setHorizontalAlignment(ALIGN_CENTER);
		add(getBarPanel());
		add(getDeckPanel());
		AdminListener.getInstance().updateAdminList();
	}

	private HorizontalPanel getBarPanel(){
		HorizontalPanel panel = new HorizontalPanel();
		panel.setSpacing(20);
		panel.add(adminList);
		panel.add(rootList);
		panel.add(accountManagement);
		panel.add(communityList);
		return panel;
	}
	
	private HorizontalPanel getDeckPanel(){
		HorizontalPanel panel = new HorizontalPanel();
		panel.setSpacing(10);
		deckPanel.add(AdminListPanel.getAdminList());
		deckPanel.add(AdminListPanel.getRootList());
		deckPanel.add(AccountManagement.getInstance());
		deckPanel.add(CommunityListPanel.getInstance());
		deckPanel.add(CommunityMember.getInstance());
		deckPanel.showWidget(ADMINLIST);
		panel.add(deckPanel);
		return panel;
	}
	
	public void showWidget(int index) {
		deckPanel.showWidget(index);
	}

	public MultiWordSuggestOracle getEmailOracle() {
		return emailOracle;
	}

	public MultiWordSuggestOracle getNameOracle() {
		return nameOracle;
	}

	public void setEmailOracle(List<String> list) {
		emailOracle.addAll(list);
	}

	public void setNameOracle(List<String> list) {
		nameOracle.addAll(list);
	}
	
}
